<?php
namespace app\admin\model;

use think\Model;
// use think\Db;
class CommentModel extends Model
{
    protected $table = 'vd_comment';




    //获取所有数据
    public function get_all_data($name=null){
        $data = $this->order('id desc')->paginate(15);
        $page = $data->render();
        return ['data'=>$data,'page'=>$page];

    }


    //获取指定类型的留言
    public function get_type_comment($name=null,$type){
        $data = $this->where(['type'=>$type])->order('id desc')->paginate(15);
        $page = $data->render();
        return ['data'=>$data,'page'=>$page];
    }

    //获取指定内容的留言
    public function get_tid_comment($name=null,$tid,$type){
        $data = $this->where(['type'=>$type,'tid'=>$tid])->order('id desc')->paginate(15);
        $page = $data->render();
        return ['data'=>$data,'page'=>$page];
    }


    public function get_data($name=null,$id){
        return $this->where('id',$id)->find();
    }


    public function do_add($name=null,$param){
        $num = $this->save($param);
        return $num;
    }

    public function do_edit($name=null,$param){
        $num = $this->isUpdate(true)->save($param);
        return $num;
    }

    public function do_delete($name=null,$id){
        $num = $this->destroy($id);
        return $num;
    }

    public function do_audit($name=null,$id){
        $num = $this->where('id',$id)->update(['status'=>1]);
        return $num;
    }

    //获取需求或研究成果
    public function get_r_d($name=null,$id,$table_name,$table_name_info,$info_id,$where='release_status'){
        $data = $this->alias('u')
                     ->where(['u.id'=>$id,$where=>1])
                     ->join($table_name.' r','u.id=r.uid')
                     ->join($table_name_info.' i','i.id=r.'.$info_id)
                     ->field('i.*,r.*')
                     ->paginate(15);
        $page = $data->render();
        return ['data'=>$data,'page'=>$page];
    }


    //搜索
    public function search_data($name=null,$where){
        $data = $this->where('title','like',$where)->paginate(15);
        $page = $data->render();
        return ['data'=>$data,'page'=>$page];
    }






}